<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" />
</head>
<body>
	<th:block th:fragment="systemJs"><script type="text/javascript" th:src="@{/js/jquery.js?v=1.12.4}"></script>
	<script type="text/javascript" th:src="@{/js/jquery.easyui.min.js?v=1.5.4.2}"></script>
	<script type="text/javascript" th:src="@{/js/easyui-formatter.js?v=1.5.4.2}"></script>
	<script type="text/javascript" th:src="@{/js/easyui-messager.js?v=1.5.4.2}"></script>
	<script type="text/javascript" th:src="@{/js/easyui-validate.js?v=1.5.4.2}"></script>
	<script type="text/javascript" th:src="@{/js/easyui-extension.js?v=1.5.4.2}"></script>
	<th:block th:switch="${#locale.language}"><script th:case="'zh'" type="text/javascript" th:src="@{/js/locale/easyui-lang-zh_CN.js?v=1.5.4.2}"></script><script th:case="*" type="text/javascript" th:src="@{/js/locale/easyui-lang-en.js?v=1.5.4.2}"></script></th:block>
	<th:block th:if="${_csrf}"><script type="text/javascript" th:inline="javascript">
	/*<![CDATA[*/
	var csrf = /*[[${_csrf.headerName}]]*/'';
	var token = /*[[${_csrf.token}]]*/'';
	$(document).ajaxSend(function(event, xhr, options) {
		xhr.setRequestHeader(csrf, token);
	});
	/*]]>*/
	</script></th:block>
	<script type="text/javascript" th:inline="javascript">
	/*<![CDATA[*/
	$(document).ajaxError(function(event, xhr, options, exc) {
		if (xhr.status == 'undefined') {return;}
		switch(xhr.status) {
		case 0:
			$.messager.error(/*[[#{msg.httpStatus.0}]]*/'网络错误');
			break;
		case 400:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.400}]]*/'错误请求');
			break;
		case 401:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.401}]]*/'未经许可');
			break;
		case 403:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.403}]]*/'禁止访问，请刷新页面重试');
			break;
		case 404:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.404}]]*/'您访问的资源不存在');
			break;
		case 405:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.405}]]*/'不允许的方法');
			break;
		case 406:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.406}]]*/'不接受');
			break;
		case 413:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.413}]]*/' 请求的文件太大');
			break;
		case 414:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.414}]]*/'URI 太长');
			break;
		case 415:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.415}]]*/'不支持的媒体类型');
			break;
		case 500:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.500}]]*/'内部服务器错误');
			break;
		case 502:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.502}]]*/'网关错误');
			break;
		case 503:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.503}]]*/'服务不可用');
			break;
		case 504:
			$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.504}]]*/'网关超时');
			break;
		default:
			if (xhr.responseText.indexOf('<title>' + /*[[#{login.title}]]*/ 'Login'
					+ '</title>') >= 0) {
				$.messager.error(/*[[#{dialog.error}]]*/'错误',
						/*[[#{msg.httpStatus.timeout}]]*/'会话超时，请重新登录',
						function() {window.top.location.href = "/";});
			} else {
				$.messager.error(xhr.status + ': ' + /*[[#{msg.httpStatus.error}]]*/'发生 HTTP 错误');
			}
		}
	});
	$(function() {
		$(document).bind('keydown', function(e) {
			var event = window.event || e;
			//屏蔽 Alt+ 方向键 →
			if ((event.altKey) && ((event.keyCode == 37) || (event.keyCode == 39))) {event.returnValue = false; return false;}
			//屏蔽F5刷新键
			if (event.keyCode == 116) {return false;}
			//屏蔽alt+R
			if ((event.ctrlKey) && (event.keyCode == 82)) {return false;}
		});
	});
	/**
	 * 导出文件（遮罩层）
	 * @param param 请求参数
	 * @param scope 遮罩层范围(body、dialog)
	 * @param msg 提示信息
	 * @param callback 回调函数
	 */
	function exportFile(param, scope, msg, callback) {
		var url = '';
		var method = 'GET';
		var asyn = true;
		var formData = null;
		var contentType = null;
		if (Object.prototype.toString.call(param) == '[object String]') {
			url = param;
		} else {
			url = param.url;
			if (typeof param.method != 'undefined') {method = param.method;}
			if (typeof param.asyn != 'undefined') {asyn = param.asyn;}
			if (typeof param.formData != 'undefined') {formData = param.formData;}
			if (typeof param.contentType != 'undefined') {contentType = param.contentType;}
		}
		var xhr = new XMLHttpRequest();
		var xmlhttprequesttime = (new Date()).getTime();
		if (url.indexOf('?') > 0) {url = url + '&xml_http_request_time=' + xmlhttprequesttime;} else {url = url + '?xml_http_request_time=' + xmlhttprequesttime;}
		xhr.open(method, url, asyn);
		if (typeof csrf != 'undefined') {xhr.setRequestHeader(csrf, token);}
		if (contentType) {xhr.setRequestHeader('content-type', contentType);}
		xhr.responseType = 'blob';
		xhr.onload = function() {
			if (this.status === 400) {
				$.messager.error('400: ' + /*[[#{msg.httpStatus.400}]]*/'错误请求');
			} else if (this.status === 404) {
				$.messager.error('404: ' + /*[[#{msg.httpStatus.404}]]*/'您访问的资源不存在');
			} else if (this.status === 500) {
				$.messager.error('500: ' + /*[[#{msg.httpStatus.500}]]*/'内部服务器错误');
			} else if (this.status === 200) {
				var disposition = this.getResponseHeader("content-disposition");
				var fileName = 'unknown';
				if (disposition) {fileName = disposition.split('filename=')[1].replace(/"/g,'');}
				var blob = this.response;
				if (blob.type && blob.type.includes('json')) {
					if (window.FileReader) {
						var reader = new FileReader();
						reader.readAsText(blob, 'utf-8');
						reader.onload = function(e) {
							var data = JSON.parse(reader.result);
							if (data.success) {$.messager.success(data.msg);} else {$.messager.error(data.msg);}
						}
					}
				} else {
					downloadBlob(blob, fileName);
				}
			} else {
				$.messager.error(this.status + ': ' + /*[[#{msg.httpStatus.error}]]*/'发生 HTTP 错误');
			}
		};
		xhr.onloadend = function() {
			$.messager.submit('close');
			if (this.status === 200) {
				if (callback && typeof(callback) === 'function') {callback();}
			} else {
				console.log(this.statusText + ': ' + this.responseURL);
			}
		};
		xhr.send(formData);
		if (arguments[3] == "" || arguments[3] == null || arguments[3] == undefined) {
			msg = $.messager.defaults.exportMsg;
		}
		$.messager.submit(scope, msg);
	}
	function downloadBlob(blob, fileName) {
		if (blob.size > 0) {
			if (typeof window.navigator.msSaveBlob !== 'undefined') {
				var file = new Blob([blob], {type: 'application/force-download'});
				window.navigator.msSaveBlob(file, fileName);
			} else {
				var link = document.createElement('a');
				link.href = window.URL.createObjectURL(blob);
				link.download = decodeURIComponent(fileName);
				$('body').append(link);
				link.click();
				$(link).remove();
			}
		} else {
			$.messager.error($.messager.defaults.exportError);
		}
	}
	/**
	* 数组转URL参数
	*/
	function parseParams(params, key) {
		var paramUri = '';
		if (params instanceof String || params instanceof Number || params instanceof Boolean) {
			paramUri += '&' + key + '=' + encodeURIComponent(params);
		} else {
			$.each(params, function(i) {
				if (typeof(this) != 'undefined' && this.toString().length > 0) {
					var k = key == null ? i : key + (params instanceof Array ? '[' + i + ']' : '.' + i);
					paramUri += '&' + parseParams(this, k);
				}
			});
		}
		return paramUri.substr(1);
	};
	/*]]>*/
	</script></th:block>
</body>
</html>